<script language="javascript">
function konfirm(){
	var total_semua=number_format($("#total_semua").val(), 0, ',','.');
	var str_pesan="Apakah Anda Yakin Ingin Melakukan Pembayaran Sebesar "+total_semua+" ?";
	return confirm(str_pesan);
}
function hitung_total_semua(){
	var total_sekali=$("#total_sekali").val();
	var total_tahunan=$("#total_tahunan").val();
	var total_bulanan=$("#total_bulanan").val();
	var total_bebas=$("#total_bebas").val();
	var total_semua=parseFloat(total_sekali)+parseFloat(total_tahunan)+parseFloat(total_bulanan)+parseFloat(total_bebas);
	$("#target_pembayaran").html(number_format(total_semua, 0, ',','.'));
	$("#total_semua").val(total_semua);
}
function hitung_tot_bebas(){
	var total=0;
	$('input[id^="nominal_bebas_"]').each(function(){
		//$angka=str_replace(".","",$nominal[$i]);
			//	$angka=str_replace(",",".",$angka);
		var text = this.value;
		var angka=text.replace(".", "");
		angka=angka.replace(".", "");
		angka=angka.replace(",", ".");
		//alert(angka);
		//var new_text = text.replace("want", "dont want");
		total += parseFloat(angka);
	});
	$('#total_bebas').val(total);
	hitung_total_semua();
}
function hitung_tot_sekali(){
	var total=0;
	$('input[id^="tagihan_sekali_"]').each(function(){
		//$angka=str_replace(".","",$nominal[$i]);
			//	$angka=str_replace(",",".",$angka);
		var text = this.value;
		var angka=text.replace(".","");
		angka=angka.replace(".", "");
		angka=angka.replace(",", ".");
		//alert('sesudah '+angka);
		//var new_text = text.replace("want", "dont want");
		total += parseFloat(angka);
	});
	$('#total_sekali').val(total);
	hitung_total_semua();
}
function hitung_tot_denda(){
	var total=0;
	$('input[class^="cls_denda"]:checkbox:checked').each(function () {
		var id=$(this).attr("komp_denda");
		var text = $("#nominal_denda_"+id).val();
		var angka=text.replace(".", "");
		angka=angka.replace(".", "");
		angka=angka.replace(",", ".");
			//var angka=$("#nilai_"+id).val());
               // total += +this.value;
		total = parseFloat(total) + parseFloat(angka);
    });
	//var total_kotak=$("#tot_nominal").val();
	$('#total_denda').val(total);
	hitung_total_semua();
}
function hitung_tot_bulanan(){
	var total=0;
		//$(':checkbox:checked.giftsRosesCheckBox').each(function () {
	$('input[class^="cls_periode_"]:checkbox:checked').each(function () {
		var id=$(this).attr("komp_bulanan");
		var text = $("#nominal_bulanan_"+id).val();
		var angka=text.replace(".", "");
		angka=angka.replace(".", "");
		angka=angka.replace(",", ".");
			//var angka=$("#nilai_"+id).val());
               // total += +this.value;
		total = parseFloat(total) + parseFloat(angka);
    });
	//var total_kotak=$("#tot_nominal").val();
	$('#total_bulanan').val(total);
	hitung_total_semua();
}
function hitung_tot_tahunan(){
	var total=0;
	$('input[class^="cls_tahunan"]:checkbox:checked').each(function () {
		var id=$(this).attr("komp_tahunan");
		var text = $("#nominal_tahunan_"+id).val();
		var angka=text.replace(".", "");
		angka=angka.replace(".", "");
		angka=angka.replace(",", ".");
			//var angka=$("#nilai_"+id).val());
               // total += +this.value;
		total = parseFloat(total) + parseFloat(angka);
    });
	//var total_kotak=$("#tot_nominal").val();
	$('#total_tahunan').val(total);
	hitung_total_semua();
}
function rupiah(komp){
	$('#'+komp).autoNumeric({
		aSep: '.', 
		aDec: ','}
	);
	hitung_tot_bebas();
}
$(document).ready(function(){
	$('#cek_tahunan').click(function () {
		$(".cls_tahunan").attr('checked', this.checked);
	});
});
var counter=1;
function hapus_row(obj){	
	 if (confirm('Apakah data akan dihapus ?')) {
  		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	}
}
function add_row_komp(id_komp,nama_komp) {
        var tombol_aksi = '<a href="javascript:void(null)" title="Hapus" onclick="hapus_row(this)"><button type="button" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></button></a>';
  		var tr = document.createElement('tr');
  		var td_nama_komp = document.createElement('td');
		var td_nominal = document.createElement('td');
		
  		var td_aksi = document.createElement('td');  		
  		var tbodi = document.getElementById("tbody_list_komp");
  		
  		td_aksi.className = 'links';
  		td_aksi.width = 15;
  		
		td_nama_komp.innerHTML = nama_komp+"<input type='hidden' name='id_komp_bebas[]' id='id_komp_"+counter+"' value='"+id_komp+"' >";
		td_nominal.innerHTML = "<input type='text' value='0' onChange=\"rupiah('nominal_bebas_"+counter+"')\" name='nominal_bebas[]' id='nominal_bebas_"+counter+"' class='form-control input-sm' size='10'>";

  		td_aksi.innerHTML = tombol_aksi;
  		
  		tr.appendChild(td_nama_komp);
		tr.appendChild(td_nominal);

  		tr.appendChild(td_aksi);
  		tbodi.appendChild(tr);
		counter++;
		
}
</script>
<!-- komponen Modal -->
<div class="modal fade" id="pop_komponen" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div id="popup_pembayaran"></div>
		</div>
	</div>
</div>
<!-- end komponen modal -->
<div id="page-wrapper">
        <!-- /.row -->
    <div class="row">
        <div class="col-sm-12">
			<div class="panel panel-default">
				<div class="panel-heading">
                    <span class="judul-page">Pembayaran Tagihan Siswa</span>
                    <span class="pull-right">
					<a class="btn btn-warning btn-xs" href="<?php echo site_url('pembayaran_semua');?>">&nbsp;Kembali</a>
				</span>
                    
                </div>
				<div class="clearfix"></div>
			</div>
			<div class="panel panel-default">
				
                <div class="panel-heading"><span class="judul-page">Data Siswa</span>
				
				<div class="clearfix"></div>
				</div>
                <div class="panel-body">
					<table class="table table-striped table-bordered table-hover table-condensed">
							<tr>
								<td style="width:200px;"><span class="pull-left judul-hub">NVA</span></td>
								<td><?php echo $detail_siswa[0]->nis;?></td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Nama</span></td>
								<td><?php echo $detail_siswa[0]->nm_lengkap;?></td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Tahun Pelajaran Aktif</span></td>
								<td><b><?php echo $tapel['th_ajaran'];?></b></td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Tahun Pelajaran Masuk</span></td>
								<td><b><?php echo $detail_siswa[0]->th_ajaran;?></b></td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Periode Bulan</span></td>
								<td><b><?php echo $periode;?></b>
								<input type="hidden" id="total_sekali" name="total_sekali" value="0" />
								<input type="hidden" id="total_tahunan" name="total_tahunan" value="0" />
								<input type="hidden" id="total_bulanan" name="total_bulanan" value="0" />
								<input type="hidden" id="total_bebas" name="total_bebas" value="0" />
								<input type="hidden" id="total_denda" name="total_denda" value="0" />
								<input type="hidden" id="total_semua" name="total_semua" value="0" />
								</td>
							</tr>
							<tr>
								<td><span class="pull-left judul-hub">Total Pembayaran</span></td>
								<td><b><div id="target_pembayaran">0</div></b></td>
							</tr>
							
						</table>
				</div>
			</div>
			<form onsubmit="return konfirm();" action="<?php echo site_url('pembayaran_semua/proses_pembayaran');?>" name="frm_bayar" id="frm_bayar" method="post">
			<div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Tagihan Pembayaran Sekali</span></div>
				<div class="panel-body">
				
					<table class="table table-striped table-bordered table-hover table-condensed">
						<thead>
						<tr>
							<th width="15">No</th>
							<th>Nama Komponen</th>
							<th>Dibayar</th>
							<th>Sisa</th>
							<th>Nominal Pembayaran</th>
							
						</tr>
						</thead>
						<?php
						if(isset($tagihan_sekali)){
							$no=1;
							foreach($tagihan_sekali as $val){
						
						?>
						<tr>
							<td><?php echo $no;?></td>
							<td><?php echo $val['nama_komp'];?></td>
							<td><?php echo number_format($val['dibayar'],0,",",".");?></td>
							<td><?php echo number_format($val['sisa'],0,",",".");?></td>
							<td>
							<input class="form-control input-sm" onChange="hitung_tot_sekali()" type="text" value="0" id="tagihan_sekali_<?php echo $no;?>" name="nominal_sekali[<?php echo $no;?>]" style="width:200px;"/>
							
<script language="javascript">
$(document).ready(function(){
	
	$('#tagihan_sekali_<?php echo $no;?>').autoNumeric({
		aSep: '.', 
		aDec: ','}
	);
});
</script>
							<input type="hidden"  name="tagihan_sekali[<?php echo $no;?>]" value="<?php echo $val['id_komponen'];?>" />
							</td>
							
							
						</tr>
						
						<?php
						$no++;
						}
						}
						?>
						
						
					
					</table>
					
				</div>	
			</div>
			
			<div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Tagihan Pembayaran Tahunan</span></div>
				<div class="panel-body">
				
					<table class="table table-striped table-bordered table-hover table-condensed">
						<thead>
						<tr>
							<th width="15"><input type="checkbox" id="cek_tahunan" /></th>
							<th>Nama Komponen</th>
							<th>Nominal</th>
							
						</tr>
						</thead>
						<?php
						if(isset($list_tahunan)){
							$no=1;
							foreach($list_tahunan as $val){
						
						?>
						<tr>
							<td><input onclick="hitung_tot_tahunan()" type="checkbox" komp_tahunan="<?php echo $no;?>" class="cls_tahunan" name="id_tahunan[<?php echo $no;?>]" id="tahunan_<?php echo $no;?>" value="<?php echo $val['id'];?>"/>
							<input type="hidden" name="id_komp_tahunan[<?php echo $no;?>]" value="<?php echo $val['id_komponen']?>" />
							</td>
							<td><?php echo $val['nama_komp'];?></td>
							
							<td><?php echo number_format($val['nominal'],0,",",".");?>
							<input type="hidden" id="nominal_tahunan_<?php echo $no;?>" name="nominal_tahunan[<?php echo $no;?>]" value="<?php echo number_format($val['nominal'],0,",",".");?>" />
							
							</td>
							
							
						</tr>
						
						<?php
						$no++;
						}
						}
						?>
						
						
					
					</table>
					
				</div>	
			</div>
			
			<div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Tagihan Pembayaran Bulanan</span></div>
				<div class="panel-body">
					<?php
					if(isset($list_komp_bulanan)){
						$count_bulanan=1;
						$count_komp=1;
						foreach($list_komp_bulanan as $val_bulanan){
					
					?>
					<table class="table table-striped table-bordered table-hover table-condensed" style="width:600px;">
						<tr>
							<td style="width:150px;"><span class="pull-left judul-hub">Nama Komponen</span></td>
							<td><b><?php echo $val_bulanan['nama_komp']?></b></td>
						</tr>
						<tr>
							<td><span class="pull-left judul-hub">Denda</span></td>
							<td><?php echo number_format($val_bulanan['denda']['denda'],0,",",".");?></td>
						</tr>
						<tr>
							<td><span class="pull-left judul-hub">Total Bayar</span></td>
							<td><?php echo number_format($val_bulanan['denda']['total_bayar'],0,",",".");?></td>
						</tr>
						<tr>
							<td><span class="pull-left judul-hub">Bayar denda</span></td>
							<td><input class="cls_denda" onClick="hitung_tot_denda()" type="checkbox" name="komponen_bulanan[<?php echo $count_komp;?>]" id="komponen_bulanan_<?php echo $count_komp;?>" komp_denda="<?php echo $count_komp;?>" value="<?php echo $val_bulanan['id_komponen'];?>" />
							<input type="hidden" id="nominal_denda_<?php echo $count_komp;?>" name="nominal_denda[<?php echo $count_komp;?>]" value="<?php echo number_format($val_bulanan['denda']['denda'],0,",",".");?>" />
							
							</td>
						</tr>
					</table>
					<?php
						if(isset($val_bulanan['tagihan'])){
							
					?>
					<table class="table table-striped table-bordered table-hover table-condensed" style="width:600px;">
						<script language="javascript">
$(document).ready(function(){
	$('#cek_periode_<?php echo $count_komp;?>').click(function () {
		$(".cls_periode_<?php echo $count_komp;?>").attr('checked', this.checked);
	});
});
</script>
						<thead>
						<tr>
							<th width="15"><input type="checkbox" id="cek_periode_<?php echo $count_komp;?>" /></th>
							<th>Periode</th>
							<th>Nominal</th>
							
						</tr>
						</thead>
						<?php
						foreach($val_bulanan['tagihan'] as $val_tagihan){
						?>
						<tr>
							<td><input onClick="hitung_tot_bulanan()" type="checkbox" komp_bulanan="<?php echo $val_tagihan['id']?>" class="cls_periode_<?php echo $count_komp;?>" value="<?php echo $val_tagihan['id']?>" name="tagihan_bulanan[<?php echo $count_bulanan;?>]" />
							<input type="hidden" name="id_komp_bulanan[<?php echo $count_bulanan;?>]" value="<?php echo $val_tagihan['id_komponen']?>" />
							</td>
							<td><?php echo $val_tagihan['str_periode']?></td>
							<td><?php echo number_format($val_tagihan['nominal'],0,",",".");?>
							<input type="hidden" id="nominal_bulanan_<?php echo $val_tagihan['id']?>"  name="nominal_bulanan[<?php echo $count_bulanan;?>]" value="<?php echo number_format($val_tagihan['nominal'],0,",",".");?>" />
							</td>
						</tr>
						<?php
							$count_bulanan++;
						}
						?>
					</table>
					<?php
					}
					?>
					<?php
						$count_komp++;
					}
					}
					?>
				</div>
			</div>
			
			<div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Pembayaran Tagihan Bebas</span></div>
				<div class="panel-body">
				
					<div class="form-group">
							<label class="col-sm-3 control-label">Jenis Komponen</label>
							<div class="col-sm-8"><p class="form-control-static">
								<span class="pull-right">
					<a href="#" class="btn btn-warning btn-xs" style="margin-bottom: 5px;" onclick="show_popup()" data-toggle="modal" data-target="#pop_komponen"><span class="glyphicon glyphicon-plus"></span>&nbsp;Tambah Komponen</a>
				</span>
				<!-- <div class="panel-body"> -->
					<table class="table table-striped table-bordered table-hover table-condensed">
						<thead>
							<tr>
								<th>Nama Komponen</th>
								<th width="35%">Nominal</th>
								<th width="40"></th>
							</tr>
						</thead>
						<tbody id="tbody_list_komp">
						</tbody>
					</table>
				<!-- </div> --></p>
							</div>
					
					
				
				</div>
			</div>
        </div>
    </div>
			
			<div class="panel panel-default">
				<div class="panel-body">
					<div class="form-group" >
                        <div class="col-sm-offset-2 col-sm-9">
						<input type="hidden" name="nis" value="<?php echo $nis;?>" />
						<input type="hidden" name="id_tapel" value="<?php echo $tapel['id_mr_th_ajaran'];?>" />
						  <input type="submit" value="Simpan" name="kirim" class="btn btn-primary btn-sm">
                          <button type="reset" class="btn btn-danger btn-sm">Reset</button>
                        </div>
                      </div>
				</div>
				</div>
		</form>
        </div>
    </div>
    <!-- /.row -->
</div>
<!-- /#page-wrapper -->
<script type="text/javascript">
    /*$('#saudaraModal').modal(options);
    $('#ortuModal').modal(options);
    $('#editSModal').modal(options);*/	
	
	function show_popup(){
		$.ajax({
			type: "POST",
			url : "<?php echo site_url(); ?>mr_komp_pembayaran/popup_komponen",
			data: "jenis=bebas",
			cache: false,
			success: function(response) {
				$('#popup_pembayaran').html(response);
			}
		});
		return false;
	}	
</script>